import { message } from "ant-design-vue";

export default function(Vue) {
  // 复制操作符
  Vue.directive("copy", {
    bind: function(el) {
      el.setAttribute("title", "点击复制");
      el.setAttribute("style", "cursor:pointer");
    },
    inserted: function(el) {
      console.log(el);
      el.addEventListener("click", async () => {
        console.log(el.innerText);
        const input = document.createElement("input");
        document.body.append(input);
        input.value = el.innerText;
        input.select();
        document.execCommand("copy", false, null);
        document.body.removeChild(input);
        message.success("已复制");
      });
    },
    unbind: function(el) {
      el.removeEventListener("click", () => {

      });
    }
  });
}

